package io.hepu.robotize.util;

import java.util.concurrent.atomic.AtomicLong;

public final class JId {
    private static final String PREFIX = "909";
    private static final AtomicLong COUNTER = new AtomicLong(System.currentTimeMillis());

    private JId() {
        // not supported instance
    }

    // Generate 13-bit time series long id value
    public static long longId() {
        return COUNTER.incrementAndGet();
    }

    public static String id() {
        return id(PREFIX);
    }

    // Generate 13-bit string id value
    public static String id(String prefix) {
        String id = String.valueOf(longId());
        return prefix.concat(id.substring(prefix.length()));
    }

    // Generate id value based on id type, either String or Long
    public static Object id(Class<?> type) {
        return type.isAssignableFrom(String.class) ? id() : longId();
    }

    // Generate id value especially for oss file name
    public static String randomId() {
        return JDate.format(JDate.now(), "YYYYMMDDhhmmss") + Randoms.getRandom(4);
    }
}
